# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface
from itemadapter import ItemAdapter
import openpyxl as openpyxl

class InstaPipeline:
     # 创建excel表
    def __init__(self):
        self.wb = openpyxl.Workbook()
        self.ws = self.wb.active
        self.ws.title = 'insta360'
        self.ws.append(['链接'])

    def open_spider(self, spider):
        print('ExcelPipeline:', '开始spider。。。。！')



    def process_item(self, item, spider):
        url = item.get('url', '')
        self.ws.append([url])
        return item
    

    def close_spider(self, spider):
        self.wb.save('insta360.xlsx')
    print('ExcelPipeline:', '关闭spider。。。。！')
